package com.sakura.动态规划;

public class Code264_丑数II {

    public int nthUglyNumber(int n) {
        int[] dp = new int[n + 1];
        dp[1] = 1;
        for (int i = 2, i2 =1, i3 =1, i5 = 1, x2, x3,x5, cur; i <= n; i++) {
            x2 = dp[i2] * 2;
            x3 = dp[i3] * 3;
            x5 = dp[i5] * 5;
            cur = Math.min(Math.min(x2, x3), x5);
            if (cur == x2) {
                i2++;
            }
            if (cur == x3) {
                i3++;
            }
            if (cur == x5){
                i5++;
            }
            dp[i] = cur;
        }
        return dp[n];
    }
}
